package futurewonder.Core;

import futurewonder.Components.ComponentsCustomiser;

import futurewonder.Utilities.Tools;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.HashMap;


public class ConnectionManager {

    

    public ConnectionManager() {
        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            System.out.println("Where is your Oracle JDBC Driver?");
            e.printStackTrace();
            return;
        }

        System.out.println("Oracle JDBC Driver Registered!");

        getConnected();
    }

    public HashMap getConnected() {
        Connection connection = null;

        HashMap hm = new HashMap();

        try {

            connection =
                    DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.3:1521/sysanonym", "APEX", "sysanonym");
            Statement stmnt = connection.createStatement();
            ResultSet rs;
            rs = stmnt.executeQuery("select * from APEX.persons");


            while (rs.next()) {
                System.out.println(rs.getString(2));
                System.out.println(rs.getString(3));

                hm.put("user", rs.getString(2));
                hm.put("Password", rs.getString(3));

                Tools.debug("check hash debug" + hm);
                Tools.debug("Check debug" + rs.getString(2));
            }

        } catch (SQLException e) {

            Tools.debug("Connection Failed! Check output console");
            e.printStackTrace();
        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }
        return hm;
    }

}
